package service

import (
	"chaowan/utils"
	"encoding/base64"
	"fmt"
	"strconv"
	"strings"
)

func Haibao(nickname string, work_name string, work_company string, addr string, work_time string, work_hourprice float64, work_monthy string, qrcodeimgurl string) string {
	//func Haibao()string {
	//	fmt.Println("---------------------")
	//	fmt.Println(nickname)
	//	fmt.Println("---------------------")
	//	fmt.Println(work_name)
	//	fmt.Println("---------------------")
	//	fmt.Println(work_company)
	//	fmt.Println("---------------------")
	//	fmt.Println(addr)
	//	fmt.Println("---------------------")
	//	fmt.Println(work_time)
	//	fmt.Println("---------------------")
	//	fmt.Println(work_hourprice)
	//	fmt.Println("---------------------")
	//	fmt.Println(work_monthy)
	//	fmt.Println("---------------------")
	//	fmt.Println(work_time)
	//qrcodeimgurl = "D:\\daima\\go\\src\\shequ\\23.png"
	qrcodeimg := []byte(qrcodeimgurl)
	qrcode := utils.Stringtihuan(base64.StdEncoding.EncodeToString(qrcodeimg))
	fmt.Println(qrcode)
	usernamey := []byte(nickname)
	username := utils.Stringtihuan(base64.StdEncoding.EncodeToString(usernamey))
	workNamey := []byte(work_name)
	workName := utils.Stringtihuan(base64.StdEncoding.EncodeToString(workNamey))
	companyy := []byte(work_company)
	company := utils.Stringtihuan(base64.StdEncoding.EncodeToString(companyy))
	workTimey := []byte(work_time)
	workTime := utils.Stringtihuan(base64.StdEncoding.EncodeToString(workTimey))
	houry := []byte(strconv.FormatFloat(work_hourprice, 'G', 4, 64))
	hour := utils.Stringtihuan(base64.StdEncoding.EncodeToString(houry))
	hour2y := []byte("元/小时")
	hour2 := utils.Stringtihuan(base64.StdEncoding.EncodeToString(hour2y))
	monthy := []byte(work_monthy)
	month := utils.Stringtihuan(base64.StdEncoding.EncodeToString(monthy))
	typesizi := "ZmFuZ3poZW5naGVpdGk" // 字体
	fmt.Println(addr)
	var address string
	var addressMark string
	var hbarr []string
	if len(addr) < 60 {
		addressy := []byte(addr)
		address = utils.Stringtihuan(base64.StdEncoding.EncodeToString(addressy))
		addressMark = "watermark,type_" + typesizi + ",size_22,text_" + address + ",color_202020,g_nw,x_101,y_360"
	}
	if len(addr) > 60 && len(addr) < 120 {
		addressy1 := []byte(addr[0:60])
		addressy2 := []byte(addr[60:])
		address = utils.Stringtihuan(base64.StdEncoding.EncodeToString(addressy1))
		address2 := utils.Stringtihuan(base64.StdEncoding.EncodeToString(addressy2))
		addressMark = "watermark,type_" + typesizi + ",size_24,text_" + address + ",color_202020,g_nw,x_101,y_360"
		addressMark2 := "watermark,type_" + typesizi + ",size_24,text_" + address2 + ",color_202020,g_nw,x_101,y_390"
		hbarr = append(hbarr, addressMark)
		hbarr = append(hbarr, addressMark2)
	}
	if len(addr) > 120 {
		addressy1 := []byte(addr[0:60])
		addressy2 := []byte(addr[60:120])
		addressy3 := []byte(addr[120:])
		address = utils.Stringtihuan(base64.StdEncoding.EncodeToString(addressy1))
		address2 := utils.Stringtihuan(base64.StdEncoding.EncodeToString(addressy2))
		address3 := utils.Stringtihuan(base64.StdEncoding.EncodeToString(addressy3))
		addressMark = "watermark,type_" + typesizi + ",size_20,text_" + address + ",color_202020,g_nw,x_101,y_350"
		addressMark2 := "watermark,type_" + typesizi + ",size_20,text_" + address2 + ",color_202020,g_nw,x_101,y_380"
		addressMark3 := "watermark,type_" + typesizi + ",size_20,text_" + address3 + ",color_202020,g_nw,x_101,y_410"
		hbarr = append(hbarr, addressMark)
		hbarr = append(hbarr, addressMark2)
		hbarr = append(hbarr, addressMark3)
	}

	workMark := "watermark,type_" + typesizi + ",size_30,text_" + workName + ",color_202020,g_nw,x_60,y_209"
	hourMark := "watermark,type_" + typesizi + ",size_30,text_" + hour + ",color_528FFF,g_nw,x_460,y_206"
	usernameMark := "watermark,type_" + typesizi + ",size_28,text_" + username + ",color_ffffff,g_nw,x_45,y_49"
	workTimeMark := "watermark,type_" + typesizi + ",size_24,text_" + workTime + ",color_202020,g_nw,x_101,y_316"
	companyMark := "watermark,type_" + typesizi + ",size_28,text_" + company + ",color_202020,g_nw,x_60,y_262"

	hour2Mark := "watermark,type_" + typesizi + ",size_20,text_" + hour2 + ",color_528FFF,g_nw,x_516,y_210"
	monthMark := "watermark,type_" + typesizi + ",size_28,text_" + month + ",color_528FFF,g_nw,x_380,y_267"
	qrcodeMark := "watermark,image_" + qrcode + ",g_se,x_60,y_30"

	hbarr = append(hbarr, workMark)
	hbarr = append(hbarr, hourMark)
	hbarr = append(hbarr, usernameMark)
	hbarr = append(hbarr, workTimeMark)
	hbarr = append(hbarr, companyMark)
	hbarr = append(hbarr, addressMark)
	hbarr = append(hbarr, hour2Mark)
	hbarr = append(hbarr, monthMark)
	hbarr = append(hbarr, qrcodeMark)
	arrstr := strings.Join(hbarr, "/")
	//fmt.Println(arrstr)
	urlstr := "http://img.jsfangdu.com/public/2021-08/612860e24a2b2.png"
	url := urlstr + "?x-oss-process=image/" + arrstr
	return url

}
